package com.typhoon.spring_shiro.dto.response;

import java.io.Serializable;

import com.alibaba.fastjson.JSON;

public class Result implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3468367070283128716L;

	private boolean success = true;

    private String code; // 消息编码

    private String message; // 消息内容
    
    private Object attach;// 消息附加对象

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getAttach() {
        return attach;
    }

    public void setAttach(Object attach) {
        this.attach = attach;
    }
    
    @SuppressWarnings("unchecked")
    public <T extends Result> T error(String message) {
        this.success = false;
        this.message = message;
        return (T) this;
    }

    @SuppressWarnings("unchecked")
    public <T extends Result> T error(String code, String message) {
        this.success = false;
        this.code = code;
        this.message = message;
        return (T) this;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }


    public String toString() {
        return JSON.toJSONString(this);
    }


}
